package com.example.springboot159.config;

import com.example.springboot159.filter.RequestBodyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean registrationBean(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        List<String> partten = new ArrayList<>();
        partten.add("/*");
        registrationBean.setFilter( new RequestBodyFilter());
        registrationBean.setUrlPatterns(partten);
        registrationBean.setName("a");
        registrationBean.setOrder(1);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean CharacterEncodingFilterBean(){
        List<String> partten = new ArrayList<>();
        partten.add("/*");
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new CharacterEncodingFilter("UTF-8"));
        registrationBean.setUrlPatterns(partten);
        return registrationBean;
    }
}
